package com.service.socket.protocol;

import java.lang.reflect.Field;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.service.bean.Road_Data;
import com.service.other.Logger;

public class Road_DataProtocol {

	protected Road_Data data;	
	protected String protocol;
	
	public Road_Data Parser(String rawData) {
		try{
			Pattern p = Pattern.compile(protocol);
			Matcher m = p.matcher(rawData);
			if (m.find()) {
				Field[] fields = data.getClass().getFields();
				for (int i = 0; i < fields.length; i++) {
					fields[i].setAccessible(true);
					String name = fields[i].getName();
					try {
						fields[i].set(data, Conversion.reversal(m.group(name)));
					} catch (Exception e) {
//						Logger.err(e);
					}
				}
			}
		}catch(Exception e){
			Logger.err(e);
		}
		return data;
	}
}
